<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
    <link href="../lib/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
    <link href="../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
<script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>用户管理</title>
</head>
<body>
    <div class="pt-5  pl-20 pr-20 pb-20">
        <form id="itemEdit" name="itemEdit" method="post" action="../ashx/spui.ashx" class="form form-horizontal">
            <input type="hidden" class="actionValue" id="editAction" name="action" value="add" />
            <input type="hidden" id="id" name="id" />
            <input type="hidden" id="fgid" name="fgid" value="" />
            <input type="hidden" id="tablename" name="tablename" value="" />
            <input type="hidden" id="tablemidname" name="tablemidname" value="" />
            <!-- <input type="hidden" id="fstate" name="fstate" value="草稿" />-->
            <input type="hidden" id="dataneedtouser" name="dataneedtouser" value="1" /><!--是否要包含通用数据必归属处理-->
            <div id="tab-category" class="HuiTab">
                <div class="tabBar cl" id="tab-categorybar"><span>单据信息</span><span>物品信息</span><span>其它信息</span></div>
                <div class="tabCon" id="divtab1">
                    <div id="divshow1">
                        <fieldset>
                            <legend style="margin-bottom: 2px;">基本信息</legend>
                            <div class="row cl" style="margin-top: 0px;">
                                <label class="form-label col-1">仓库：</label>
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="fstoreid" id="fstoreid" nullmsg="请选择"></select>
                                    </span>
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">类型：</label>
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="ftype" id="ftype" nullmsg="请选择">
                                            <option value="出库">出库</option>
                                            <option value="入库">入库</option>
                                        </select></span>
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">原由：</label>
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="fsontype" id="fsontype" nullmsg="请选择">
                                        </select></span>
                                </div>
                                <div class="col-1"></div>
                            </div>
                            <div class="row cl">
                                <label class="form-label col-1">生产编号：</label>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="forderNo" id="forderNo" placeholder="对应的生产订单编号" />
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">单据说明：</label>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="fsontypeinfo" id="fsontypeinfo" placeholder="单据说明、生产订单说明" />
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">状态：</label>
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="fstate" id="fstate"  onchange="this.selectedIndex=1" nullmsg="请选择">
                                            <option value="草稿">草稿</option>
                                            <option value="完成">完成－－同步库存＋</option>
                                            <option value="作废">作废－－同步库存－</option>
                                        </select></span>
                                </div>
                            </div>
                        </fieldset>
                        <fieldset>
                            <legend style="margin-bottom: 2px;">重要关系方信息</legend>
                            <div class="row cl" style="margin-top: 0px;">
                                <label class="form-label col-1">类型：</label>
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="finoutusertype" id="finoutusertype">
                                            <option value="供应商">供应商</option>
                                            <option value="客户">客户</option>
                                            <option value="员工">员工</option>
                                        </select></span>
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">名称：</label>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="finoutusername" id="finoutusername" readonly="readonly" placeholder="右边选择或搜索选择" />
                                    <input type="hidden" id="finoutuserid" name="finoutuserid" />
                                </div>

                                <div class="col-3 layui-form">
                                    <select name="inoutusernamesel" id='inoutusernamesel' lay-filter="testselect" lay-verify="required" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row cl">
                                <label class="form-label col-1">联系人：</label>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="finoutuserteluser" id="finoutuserteluser" placeholder="联系人" />
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">电话：</label>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="finoutusertel" id="finoutusertel" placeholder="联系方式" />
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">地址：</label>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="finoutuseraddress" id="finoutuseraddress" placeholder="地址" />
                                </div>
                                <div class="col-1"></div>
                            </div>
                        </fieldset>
                    </div>
                </div>
                <div class="tabCon" id="divtab2">
                    <div id="divshow2">
                        <fieldset>
                            <legend style="margin-bottom: 2px;">物品操作</legend>
                            <div class="row cl" style="margin-top: 0px;">
                                <label class="form-label col-2" style="text-align: center;">主分类</label>
                                <label class="form-label col-2" style="text-align: center;">子分类</label>
                                <label class="form-label col-2" style="text-align: center;">物品</label>
                                <label class="form-label col-2" style="text-align: center;">数量</label>
                                <label class="form-label col-2" style="text-align: center;">单价</label>
                                <label class="form-label col-2" style="text-align: center;">单位</label>
                            </div>
                            <div class="row cl" style="margin-top: 0px;">
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="selfproducttype" id="selfproducttype"></select></span>
                                </div>
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="selfproductclass" id="selfproductclass"></select>
                                    </span>
                                </div>
                                <div class="col-2 layui-form">
                                    <select name="selherp_product" id='selherp_product' lay-filter="selherp_product" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                    </select>
                                </div>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="selcount" id="selcount" value="1" datatype="/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/" />
                                </div>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="selprice" id="selprice" value="1" datatype="/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/" />
                                </div>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" name="selunit" id="selunit" value="单位" />
                                </div>
                                <div class="formControls col-2">
                                    <button onclick="addOrderSpListInfo();" class="btn btn-danger radius" type="button">添加</button>
                                  <!--  <button onclick="UpdateZjGs();" class="btn btn-danger radius" type="button">保存</button>-->
                                </div>
                            </div>

                        </fieldset>
                        <fieldset>
                            <legend style="margin-bottom: 2px;">物品列表</legend>
                            <table class="table table-border table-bordered table-striped table-hover" id="tablelist" width="100%">
                                <thead>
                                    <tr class="text-c">
                                        <th width="30"><a id="hcmtable_sall" onclick="hcmtable_sall();" href="javascript:;" title="全选反选"><i class="Hui-iconfont">&#xe608;全</i></a></th>
                                        <th>ID</th>
                                        <th>主分类</th>
                                        <th>子分类</th>
                                        <th>名称</th>
                                        <th>金额</th>
                                        <th>数量</th>
                                        <th>总额</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </fieldset>
                    </div>
                </div>
                <div class="tabCon" id="divtab3">
                    <div id="divshow3">
                    </div>
                </div>
            </div>
            <div class="cl" style="display: none;" id="fold_category">
                <ul id="Huifold2" class="Huifold">
                    <li class="item">
                        <h4>单据信息<b>+</b></h4>
                        <div class="info" id="divfold1" style="display: block;">
                        </div>
                    </li>
                    <li class="item">
                        <h4>基本设置2<b>+</b></h4>
                        <div class="info" id="divfold2" style="display: block;">
                        </div>
                    </li>
                    <li class="item">
                        <h4>基本设置3<b>+</b></h4>
                        <div class="info" id="divfold3" style="display: block;"></div>
                    </li>
                </ul>
            </div>
            <div class="row cl">
                <div class="col-6 col-offset-4">
                    <button onclick="changeshowtype();" class="btn btn-danger radius" type="button">切换显示</button>&nbsp;&nbsp;&nbsp;&nbsp;
                    <button class="btn btn-primary radius" type="submit" id="btsub1" >提交</button>&nbsp;&nbsp;
				<button class="btn btn-secondary radius" type="button" id="btn_reset">重置</button>&nbsp;&nbsp;
                  <button onclick="printPDF();" class="btn btn-default radius" type="button">打印</button>
                    <button onclick="layer_close();" class="btn btn-default radius" type="button">返回</button>
                </div>
            </div>
            <div class="row cl">
                <div class="col-10" id="divforhcrfbutton">
                </div>
            </div>
        </form>
    </div>
    <iframe style="display: none" id="printIframe"></iframe>
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="../lib/Validform/5.3.2/Validform.js"></script>
    <script type="text/javascript" src="../lib/layer/1.9.3/layer.js"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hcui.js"></script>
    <script type="text/javascript" src="../js/hcui_au.js"></script>
    <script type="text/javascript" src="../js/hcrainwf.js"></script>
    <!--   <script type="text/javascript" src="../lib/My97DatePicker/WdatePicker.js"></script>-->

    <script type="text/javascript" src="../lib/datatables/1.10.0/jtable.js"></script>
    <script type="text/javascript" src="../js/hcui_list.js"></script>
    <!-- 文件上传方法SSSSSSSSSSSSSSS-->
    <!--    <link href="../uploadifyjs/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="../uploadifyjs/swfobject.js" type="text/javascript"></script>
    <script src="../uploadifyjs/jquery.uploadify.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../newbasejs/uploadifyui.js"></script>-->
    <!-- 文件上传方法EEEEEEEEEEEEEEE-->
    <script type="text/javascript">
        var uiform = null;
      


        var divshowtype = 1;
        HcUiAuloadInfoAuto = false;//将自动加载，设置为false（禁用自动加载）
        var loadisOk = 1;
        //初始化
        $('#fsontype').append('<option value="发货出库">发货出库-出库</option>');
        $('#fsontype').append('<option value="生产取料">生产取料-出库</option>');
        $('#fsontype').append('<option value="销售出库">销售出库-出库</option>');
        $('#fsontype').append('<option value="其它出库">其它出库-出库</option>');

        $('#ftype').change(function () {
            var type = $(this).children('option:selected').val();
            $('#fsontype').children().remove();
            if (type == '出库') {
                $('#fsontype').append('<option value="发货出库">发货出库-出库</option>');
                $('#fsontype').append('<option value="生产取料">生产取料-出库</option>');
                $('#fsontype').append('<option value="销售出库">销售出库-出库</option>');
                $('#fsontype').append('<option value="其它出库">其它出库-出库</option>');
                $("#fsontype").change();
            }
            else if (type == '入库') {
                $('#fsontype').append('<option value="生产采购">生产采购-入库</option>');
                $('#fsontype').append('<option value="生产完成入库">生产完成-入库</option>');
                $('#fsontype').append('<option value="日常采购">日常采购-入库</option>');
                $('#fsontype').append('<option value="其它入库">其它入库-入库</option>');
                $("#fsontype").change();
            }

        });
        $('#fsontype').change(function () {
            var type = $(this).children('option:selected').val();
            if (type == "发货出库" || type == "销售出库" || type == "其它出库" || type == "生产完成入库")//客户
            {
                $("#finoutusertype").val('客户');
                //加载客户
            }
            else if (type == "生产取料")//员工
            {
                $("#finoutusertype").val('员工');
                //加载员工
            }
            else if (type == "日常采购" || type == "其它入库" || type == "生产采购")//供应商
            {
                $("#finoutusertype").val('供应商');
                //加载供应商
            }
            $('#finoutusertype').change();
        });
        //当前关联对象信息--人员
        var inoutusernameselObj = [];
        //当前关联对象信息--物品
        var inoutproductObj = [];
        $('#finoutusertype').change(function () {
            var type = $(this).children('option:selected').val();
            if (type == "客户")//客户
            {
                hcdosel("id,name,username,tel,address", "herp_customer", "type='客户'", "", "", "id", function (data) {
                    SetSelectWithObjIdName("#inoutusernamesel", data);
                    inoutusernameselObj = JSON.parse(data);
                    uiform.render('select');
                });
            }
            else if (type == "员工")//员工
            {
                hcdosel("empid  as id,concat(depname,'-',empname) as name,empname as username,mobile as  tel,depname as address", "view_user", "", "", "", "id", function (data) {
                    SetSelectWithObjIdName("#inoutusernamesel", data);
                    inoutusernameselObj = JSON.parse(data);
                    uiform.render('select');
                });
            }
            else if (type == "供应商") {
                hcdosel("id,name,username,tel,address", "herp_customer", "type='供应商'", "", "", "id", function (data) {
                    SetSelectWithObjIdName("#inoutusernamesel", data);
                    inoutusernameselObj = JSON.parse(data);
                    uiform.render('select');
                });
            }
        });
        //物品主分类
        hcdosel("dictdata_code as id,dictdata_name as name", "dictionarydata", "dict_code='ErpProductMtype'", "", "", "orderindex",
               function (data) {
                   SetSelectWithObjIdName("#selfproducttype", data);
               });
        //连动 联动 加载子分类
        $('#selfproducttype').change(function () {
            loadProductclass($(this).children('option:selected').val());
        });
        //加载子分类
        function loadProductclass(type, selid) {
            if (type == "") return;
            hcdosel("dictdata_code as id,dictdata_name as name", "dictionarydata", "dict_code='ErpProductStype' and parent_code='" + type + "' ", "", "", "orderindex",
                function (data) {
                    SetSelectWithObjIdName("#selfproductclass", data);
                    if (selid) $("#selfproductclass").val(selid);
                });
        }

        //物品子分类
        //hcdosel("dictdata_code as id,dictdata_name as name", "dictionarydata", "dict_code='ErpProductStype'", "", "", "orderindex",
        //     function (data) {
        //         SetSelectWithObjIdName("#selfproductclass", data);

        //     });
        //物品明细
        $('#selfproductclass').change(function () {
            var type = $(this).children('option:selected').val();
            if (type == "") {
                hcdosel("id,concat(productno,'-',name) as name,unit", "herp_product", "productclass='清空'", "", "", "id", function (data) {
                    SetSelectWithObjIdName("#selherp_product", data);
                    inoutproductObj = JSON.parse(data);
                    uiform.render('select');
                });
            }
            else {
                hcdosel("id,concat(productno,'-',name) as name,unit", "herp_product", "productclass='" + type + "'", "", "", "id", function (data) {
                    SetSelectWithObjIdName("#selherp_product", data);
                    inoutproductObj = JSON.parse(data);
                    uiform.render('select');
                });
            }
        });
        //加载处理
        function loadin() {
            layui.use(['form'], function () {
                uiform = layui.form();
                uiform.on('select(testselect)', function (data) {
                    $('#finoutuserid').val(data.value);
                    $('#finoutusername').val($("#inoutusernamesel").find("option:selected").text());
                    //加载明细
                    var objget = hcgetJsonObjById(inoutusernameselObj, data.value);
                    $('#finoutuserteluser').val(objget.username);
                    $('#finoutusertel').val(objget.tel);
                    $('#finoutuseraddress').val(objget.address);
                });
                uiform.on('select(selherp_product)', function (data) {
                    $('#selunit').val(hcgetJsonObjById(inoutproductObj, data.value).unit);
                });

            });
            $("#printIframe").load(function () {//等待iframe加载完成后再执行doPrint.每次iframe设置src之后都会重新执行这部分代码。
                doPrint();
            });


            if (getUrlParam("action") == "add") {
                $("#fgid").val(NewGuid());
                $('#finoutusertype').change();
            }
            //本页面 
            spsetBase("herp_inoutorder", "id", "herp_inoutorder as T", "*", "#tablelist", "herp_inoutorder", "出入库管理", "StoreInOut");
            //$("#imgExist").attr("src", "../ashx/GetPhotoHandler.ashx?mid=" + PhotoId);
            //数据加载
            hcdosel("id,name", "herp_storehouse", "", "", "", "id", function (data) {
                SetSelectWithObjIdName("#fstoreid", data);
                $('#fstoreid option:eq(1)').attr('selected', 'selected');//选择第二(1)个
                loadisOk--;
                if (loadisOk <= 0 && auhcotype == "edit") {
                    loadInfoById(aumid, function (data) {
                        loadback(data);
                    });
                }
            });

            $.Huitab("#tab-category .tabBar span", "#tab-category .tabCon", "current", "click", "0");
            $.Huifold("#Huifold2 .item h4", "#Huifold2 .item .info", "", 3, "click"); /*5个参数顺序不可打乱，分别是：相应区,隐藏显示的内容,速度,类型,事件 mouseover click */
            ////三种类型：分别对应的参数：1	只打开一个，可以全部关闭2	必须有一个打开3	可打开多个

        }
        function loadback(data) {
            console.log(data);
            $('#ftype').change();//主分类
            $("#fsontype").val(data["sontype"]);//重新 设置子分类
            $("#finoutusertype").val(data["inoutusertype"]);//重新 对象分类
            $('#finoutusertype').change();
        }
        //切换事件
        function changeshowtype() {
            if (divshowtype == 1) {
                $("#divshow1").appendTo("#divfold1");
                $("#divshow2").appendTo("#divfold2");
                $("#divshow3").appendTo("#divfold3");
                $("#fold_category").show();
                $("#tab-category").hide();

                divshowtype = 2;
            }
            else {
                $("#divshow1").appendTo("#divtab1");
                $("#divshow2").appendTo("#divtab2");
                $("#divshow3").appendTo("#divtab3");
                $("#fold_category").hide();
                $("#tab-category").show();
                divshowtype = 1;
            }

        }


        //点击打印按钮，触发事件】
        function printPDF() {
            var src = $("#printIframe").attr("src");
            if (!src) {//当src为空，即第一次加载时才赋值，如果是需要动态生成的话，那么条件要稍稍变化一下
                $("#printIframe").attr("src", "../printfiles/1.pdf");//暂时静态PDF文件

                //$.get("pr.ashx", function (data) {
                //    $("#printIframe").attr("src", data);//获取地址

                //});
            } else { doPrint(); }
        }
        function doPrint() {
            $("#printIframe")[0].contentWindow.print();
        }
        function printPDF2() {
            window.open('pr.ashx', "_blank");
        }
        var loadbackdata = [];
        //加载完成后,加载明细列表
        function loadback(data) {
            loadbackdata = data;
            if (loadbackdata.state == '完成')//已完成，不能修必出入库状态
            {
                var osel = document.getElementById("ftype");
                osel.onfocus = function () {
                    this.defaultIndex = this.selectedIndex;
                }
                osel.onchange = function () {
                    this.selectedIndex = this.defaultIndex;
                }
                $("#btsub1").hide();
            }
            hcmtable = $("#tablelist").DataTable({
                "serverSide": true,//服务端处理分页 无法使用当前查找
                "bFilter": false,  //是否使用内置的过滤功能
                "bLengthChange": false, //改变每页显示数据数量
                "ajax": {
                    "type": "POST",
                    "url": sposelUrl("herp_inoutorderlist", "id,gid,ordergid,spid,spname,count,price,state,'desc',storeid,spmaintype,spsubtype,(count * price) as allmoney", " and ordergid='" + $("#fgid").val() + "'") + "&sporderby=id",
                    "data": function (d) {
                    }
                },
                aLengthMenu: [100],
                "columns": [
                     { "data": "rowhcindex" },
                     { "data": "id" }
        , { "data": "spmaintype" }
        , { "data": "spsubtype" }
        , { "data": "spname" }
        , { "data": "price" }
        , { "data": "count" }
        , { "data": "allmoney" }
        , { "data": "id" }

                ],
                "columnDefs": [

                    {
                        "targets": [8],
                        "render": function (data, type, row) {
                            if (loadbackdata.state == '完成')
                            { return "当前状态不能操作"; }
                            else 
                            return "<a style=\"text-decoration:none\" class=\"ml-5\" onclick=\"LoadZjGs(" + row.id + ")\" href=\"javascript:;\" title=\"编辑\"><i class=\"Hui-iconfont\">&#xe6df;编辑</i></a> " +
                                   "<a style=\"text-decoration:none\" class=\"ml-5\" onclick=\"toolDelete('" + data + "','herp_inoutorderlist','id')\"     href=\"javascript:;\" title=\"删除\"><i class=\"Hui-iconfont\">&#xe6e2;删除</i></a>";
                        }
                    },

                {
                    "orderable": false,
                    "targets": [0, 1, 2, 3, 4, 5, 6, 7, 8]
                }
                ]
            });
        }
        //添加商品明细
        function addOrderSpListInfo() {
            if (loadbackdata.state == '完成')
            {
                layer.msg('当前状态不能操作', { icon: 1 });
                return;
            }
            var addinfo = "gid%" + NewGuid()
                + "$ordergid%" + $("#fgid").val()
                + "$spmaintype%" + $("#selfproducttype").find("option:selected").text()
                + "$spsubtype%" + $("#selfproductclass").find("option:selected").text()
                + "$spid%" + $("#selherp_product").val()
                + "$spname%" + $("#selherp_product").find("option:selected").text()
                + "$count%" + $("#selcount").val()
                + "$price%" + $("#selprice").val()
            + "$unit%" + $("#selunit").val();

            hcdoadd("herp_inoutorderlist", addinfo, function (info) {
                if (info == "ok") hcmtable.ajax.reload();

            });
        }

    </script>
</body>
</html>
